package com.d17_homework.homework2;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class Demo2 {
    public static void main(String[] args) throws Exception {
        //获取字节码对象
        Class<Student2> clazz =(Class<Student2>) Class.forName("com.d17_homework.homework2.Student2");
        //获取构造器对象
        Constructor<Student2> con = clazz.getDeclaredConstructor(String.class, int.class);
        con.setAccessible(true);//取消访问检查
        //创建对象
        Student2 stu = con.newInstance("赤兔", 5);
        //获取方法
        Method method = clazz.getDeclaredMethod("showInfo");
        method.setAccessible(true);//取消访问检查
        //执行方法
        method.invoke(stu);
    }
}
